package com.example.threadgroup;

/**
 * @author:CrazyShaQiuShi
 * @email:3105334046@qq.com
 * @descript:
 * @version:1.0.0
 */
public class ThreadGroupDemo implements Runnable {
    public void run() {
        String groupAndName=Thread.currentThread().getThreadGroup().getName()+"-"+Thread.currentThread().getName();
        while (true){
            System.out.println("I am "+groupAndName);
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }


    public static void main(String[]args){
        ThreadGroup group=new ThreadGroup("PrintGroup");
        Thread thread1=new Thread(group,new ThreadGroupDemo(),"thread1");
        Thread thread2=new Thread(group,new ThreadGroupDemo(),"thread2");
        thread1.start();
        thread2.start();
        System.out.println(group.activeCount());
        group.list();
    }
}
